//
//  ExchangeController.m
//  quxiangtao
//
//  Created by HHuajiang on 2018/11/21.
//  Copyright © 2018 shanhaijin. All rights reserved.
//

#import "ExchangeController.h"
#import "TapSliderScrollView.h"
#import "IntegralController.h"
#import "WelfareExchangeIntegralViewController.h"
#import "WelfareIntegralRecordViewController.h"
#import "QuDouJifenController.h"
@interface ExchangeController ()<SliderLineViewDelegate>
@property (nonatomic, assign) NSInteger selectType;
@property (nonatomic, strong) IntegralController *vc2;
@end

@implementation ExchangeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.selectType = 0;
    
    self.vc2 = [[IntegralController alloc]init];
    self.vc2.dict = self.dic;
    WelfareExchangeIntegralViewController *vc1 = [[WelfareExchangeIntegralViewController alloc]init];
    vc1.dict = self.dic;
    TapSliderScrollView *view = [[TapSliderScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    view.delegate = self;
    //设置滑动条的颜色
    view.sliderViewColor = [UIColor greenColor];
    view.titileColror = [UIColor blackColor];
    view.selectedColor = [UIColor redColor];//x
    [view createView:@[@"兑换余额",@"全民速配"] andViewArr:@[vc1,self.vc2] andRootVc:self];
    [self.view addSubview:view];
    
    UIButton*btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10, Height_StatusBar+10, jisuan(42), jisuan(42));
    [btn setBackgroundImage:[UIImage imageNamed:@"nav_go_white"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"nav_go_white"] forState:UIControlStateSelected];
    [btn setBackgroundImage:[UIImage imageNamed:@"nav_go_white"] forState:UIControlStateHighlighted];
        [btn addTarget:self action:@selector(goBackAction)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    UIButton *rightBtn = [[UIButton alloc] init];
    [rightBtn setTitle:@"兑换记录" forState:UIControlStateNormal];
    [rightBtn setTitle:@"兑换记录" forState:UIControlStateSelected];
    rightBtn.titleLabel.font = Font(24);
    rightBtn.titleLabel.textColor = WhiteColor;
    [self.view addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.equalTo(btn.mas_bottom).offset(-2);
        make.size.mas_equalTo(CGSizeMake(50, font(24)));
    }];
    
    [rightBtn addTarget:self action:@selector(rigthBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)rigthBtnClick {
    WS(weakSelf);
    if (self.selectType == 0) {
        WelfareIntegralRecordViewController *vc = [[WelfareIntegralRecordViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        QuDouJifenController *ctr = [[QuDouJifenController alloc] init];
        ctr.changeButtonClickBlock = ^{
            [weakSelf.vc2 loadDataWithTop:@"1"];
            [weakSelf.vc2 loadDataWithTop:@"2"];
        };
        [self.navigationController pushViewController:ctr animated:YES];
    }
}

- (void)goBackAction {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark sliderDelegate
-(void)sliderViewAndReloadData:(NSInteger)index
{
    self.selectType = index;
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    
}


@end
